#include <stdlib.h>
#include <juanmabc.h>

int
main(int argc, const char **argv)
{
	if(argc == 4)
	{
		if(!strcmp(argv[1], "Material"))
		{
			unsigned int str, mat;

			jmbcCreateContext();
			tlGenStrings(1, &str);
			mlGenMaterials(1, &mat);
			tlStringLoadC(str, argv[2]);
			mlMaterialCompile(mat, str);
			tlStringUnload(str);
			tlStringLoadC(str, argv[3]);
			mlMaterialSave(mat, str);
			tlStringUnload(str);
			mlMaterialUnload(mat);
			mlDeleteMaterials(1, &mat);
			tlDeleteStrings(1, &str);
			jmbcDestroyContext();
		}
		if(!strcmp(argv[1], "Mesh"))
		{
			unsigned int str, msh;

			jmbcCreateContext();
			tlGenStrings(1, &str);
			mlGenMeshes(1, &msh);
			tlStringLoadC(str, argv[2]);
			mlMeshCompile(msh, str);
			tlStringUnload(str);
			tlStringLoadC(str, argv[3]);
			mlMeshSave(msh, str);
			tlStringUnload(str);
			mlMeshUnload(msh);
			mlDeleteMeshes(1, &msh);
			tlDeleteStrings(1, &str);
			jmbcDestroyContext();
		}
		else if(!strcmp(argv[1], "Model"))
		{
			unsigned int str, mdl;

			jmbcCreateContext();
			tlGenStrings(1, &str);
			mlGenModels(1, &mdl);
			tlStringLoadC(str, argv[2]);
			mlModelCompile(mdl, str);
			tlStringUnload(str);
			tlStringLoadC(str, argv[3]);
			mlModelSave(mdl, str);
			tlStringUnload(str);
			mlModelUnload(mdl);
			mlDeleteModels(1, &mdl);
			tlDeleteStrings(1, &str);
			jmbcDestroyContext();
		}
	}
	else
		wprintf(L"%hs 'Material/Mesh/Model' From To\n", argv[0]);

	return EXIT_SUCCESS;
}
